/**
 * Copyright (c) 2013-Now http://jeesite.com All rights reserved.
 */
package com.jeesite.modules.ajz.web;

import com.github.sd4324530.fastweixin.company.api.config.QYAPIConfig;
import com.jeesite.common.config.Global;
import com.jeesite.common.entity.Page;
import com.jeesite.common.io.FileUtils;
import com.jeesite.common.lang.DateUtils;
import com.jeesite.common.lang.StringUtils;
import com.jeesite.common.utils.excel.ExcelExport;
import com.jeesite.common.web.BaseController;
import com.jeesite.common.web.CookieUtils;
import com.jeesite.common.web.http.ServletUtils;
import com.jeesite.modules.ajz.entity.*;
import com.jeesite.modules.ajz.service.*;
import com.jeesite.modules.sys.entity.EmpUser;
import com.jeesite.modules.sys.entity.Employee;
import com.jeesite.modules.sys.entity.Office;
import com.jeesite.modules.sys.entity.User;
import com.jeesite.modules.sys.service.EmpUserService;
import com.jeesite.modules.sys.service.OfficeService;
import com.jeesite.modules.sys.utils.EmpUtils;
import com.jeesite.modules.sys.utils.UserUtils;
import com.jeesite.modules.sys.wx.fw.utils.ResultTemplateMsgUtil;
import com.jeesite.modules.sys.wx.qy.py.WeixinJSSDKSignUtil;
import com.jeesite.modules.sys.wx.qy.util.DloadImgUtil;
import com.jeesite.modules.sys.wx.qy.util.QyConfigUtil;
import org.apache.ibatis.annotations.Param;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.File;
import java.io.IOException;
import java.util.*;

import static com.jeesite.modules.sys.utils.Timestamp.TIMESTAMP;

/**
 * 店面信息表Controller
 *
 * @author esan
 * @version 2019-06-24
 */
@Controller
@RequestMapping(value = "${adminPath}/ajz/ajzStoreInfo")
public class AjzStoreInfoController extends BaseController {

    @Autowired
    private AjzStoreInfoService ajzStoreInfoService;
    @Autowired
    private AjzNaturalGasService ajzNaturalGasService;
    @Autowired
    private AjzFoodSafetyService ajzFoodSafetyService;
    @Autowired
    private AjzLiquefiedGasService ajzLiquefiedGasService;
    @Autowired
    private AjzRecordService ajzRecordService;
    @Autowired
    private AjzCheckService ajzCheckService;
    @Autowired
    private AjzRecordProcessService ajzRecordProcessService;
    @Autowired
    private EmpUserService empUserService;
    @Autowired
    private AjzModelService ajzModelService;
    @Autowired
    private AjzModelContentService ajzModelContentService;
    @Autowired
    private OfficeService officeService;
    @Autowired
    private AjzCompanyInfoService ajzCompanyInfoService;

    //审核结果通知
    @Autowired
    private ResultTemplateMsgUtil resultTemplateMsgUtil;
    /**
     * 获取数据
     */
    @ModelAttribute
    public AjzStoreInfo get(String id, boolean isNewRecord) {
        return ajzStoreInfoService.get(id, isNewRecord);
    }

    /**
     * 企业信息页面
     * @param ajzStoreInfo
     * @param model
     * @return
     */
    @RequiresPermissions("sys:empUser:view")
    @RequestMapping(value = "index")
    public String index(AjzStoreInfo ajzStoreInfo, Model model) {
        return "modules/ajz/ajzStoreInfoIndex";
    }

    /**
     * 查询列表
     */
    @RequiresPermissions("ajz:ajzStoreInfo:view")
    @RequestMapping(value = {"list", ""})
    public String list(AjzStoreInfo ajzStoreInfo, Model model) {
        model.addAttribute("ajzStoreInfo", ajzStoreInfo);
        return "modules/ajz/ajzStoreInfoList";
    }

    /**
     * 查询列表数据
     */
    @RequiresPermissions("ajz:ajzStoreInfo:view")
    @RequestMapping(value = "listData")
    @ResponseBody
    public Page<AjzStoreInfo> listData(AjzStoreInfo ajzStoreInfo, HttpServletRequest request, HttpServletResponse response) {
        ajzStoreInfo.setPage(new Page<>(request, response));
        Page<AjzStoreInfo> page = ajzStoreInfoService.findPage(ajzStoreInfo);
        return page;
    }

    /**
     * 查看编辑表单
     */
    @RequiresPermissions("ajz:ajzStoreInfo:view")
    @RequestMapping(value = "form")
    public String form(AjzStoreInfo ajzStoreInfo, Model model) {
        model.addAttribute("ajzStoreInfo", ajzStoreInfo);
        return "modules/ajz/ajzStoreInfoForm";
    }

    /**
     * 保存店面信息表
     */
    @RequiresPermissions("ajz:ajzStoreInfo:edit")
    @PostMapping(value = "save")
    @ResponseBody
    public String save(@Validated AjzStoreInfo ajzStoreInfo) {
        ajzStoreInfoService.save(ajzStoreInfo);
        return renderResult(Global.TRUE, text("保存店面信息表成功！"));
    }

    /**
     * 删除店面信息表
     */
    @RequiresPermissions("ajz:ajzStoreInfo:edit")
    @RequestMapping(value = "delete")
    @ResponseBody
    public String delete(AjzStoreInfo ajzStoreInfo) {
        ajzStoreInfoService.delete(ajzStoreInfo);
        return renderResult(Global.TRUE, text("删除店面信息表成功！"));
    }

//==========================================以下是企业号的方法,序号代表流程中所在位置=========================================================

    /**
     * 跳转至专题页
     * @param model
     * @return
     */
    @RequestMapping({"typeStore"})
    public String typeStore(Model model){
        model.addAttribute("Timestamp", TIMESTAMP);//时间戳
        model.addAttribute("tableType","ajzStoreInfo");
        return "modules/ajz/mobile/type_store";
    }

    /**
     * 实时获取店面专题的数据信息
     * @param status
     * @return
     */
    @RequestMapping("detailsMap")
    @ResponseBody
    public List<?> etailsMap(@Param("status") String status,@Param("dangerType") String dangerType){
        List<AjzStoreInfo> allList = new ArrayList<>();
        AjzStoreInfo title = new AjzStoreInfo();
        AjzStoreInfo ajzStoreInfo = new AjzStoreInfo();
        //设置查询条件为店面
        AjzRecord ajzRecord = new AjzRecord();
        ajzRecord.setStatus("0");//设置企业的记录为未删除的
        ajzRecord.setBaseType("store");//设置企业类型，用于查询企业类型的值
        ajzRecord.setTableType(dangerType);
        //查询有排查过的对应企业，默认为所有
        ajzStoreInfo.setAjzRecord(ajzRecord);
        //获取默认页数
        Page page = new Page();
        page.setPageSize(10);
        page.setPageNo(1);
        ajzStoreInfo.setPage(page);
        /*1.获取标题栏数据*/
        //全部
        int all =ajzStoreInfoService.findAllList().size();
        //待整改
        ajzStoreInfo.getAjzRecord().setCheckStatus("1");
        int uncheck = (int)ajzStoreInfoService.findCount(ajzStoreInfo);
        ajzStoreInfo.getAjzRecord().setCheckStatus("2");
        uncheck += (int)ajzStoreInfoService.findCount(ajzStoreInfo);
        //已整改
        ajzStoreInfo.getAjzRecord().setCheckStatus("3");
        int checked = (int)ajzStoreInfoService.findCount(ajzStoreInfo);
        //待排查
        int uninspect =all-uncheck-checked;
        title.setAll(all);
        title.setUninspect(uninspect);
        title.setUncheck(uncheck);
        title.setChecked(checked);
        title.setStatus(status);//这里临时用作表示选中的标题栏

        /*2.获取对应过滤的数据列表*/
        switch (Integer.parseInt(status)){
            case 0://全部
                allList = ajzStoreInfoService.findAllList();
                break;
            case 1://待排查
                List<String> recordBaseId = new ArrayList();
                List<String> storeBaseId = new ArrayList();

//                ajzRecord.setCheckStatus("4");
                for(AjzRecord record:ajzRecordService.findList(ajzRecord)){
                    recordBaseId.add(record.getBaseId());
                }
                for(AjzStoreInfo StoreInfo:ajzStoreInfoService.findAllList()){
                    storeBaseId.add(StoreInfo.getId());
                }

                storeBaseId.removeAll(recordBaseId);


                //同时包含检查状态为4的
                ajzRecord.setCheckStatus("4");
                recordBaseId.clear();
                for(AjzRecord record:ajzRecordService.findList(ajzRecord)){
                    recordBaseId.add(record.getBaseId());
                }
                storeBaseId.addAll(recordBaseId);
                //获取
                for(String id:storeBaseId){
                    allList.add(ajzStoreInfoService.getById(id));
                }

                break;
            case 2://待整改
                ajzStoreInfo.getAjzRecord().setCheckStatus("1");
                allList = ajzStoreInfoService.findList(ajzStoreInfo);

                //将状态为 1和2的有隐患问题,合并
                ajzStoreInfo.getAjzRecord().setCheckStatus("2");
                allList.addAll(ajzStoreInfoService.findList(ajzStoreInfo));

                break;
            case 3://已整改
                ajzStoreInfo.getAjzRecord().setCheckStatus("3");
                allList = ajzStoreInfoService.findList(ajzStoreInfo);
                break;
        }

        /*如果存在数据则给标题栏赋值*/
        if(title.getAll()!=0){
            allList.add(title);
        }

        return allList;
    }

    //修改:跳转到店面修改页面
    @RequestMapping(value = "updateInfo")
    public String updateInfo(AjzStoreInfo ajzStoreInfo,HttpServletRequest request, HttpServletResponse response, Model model) {
        //查询企业的基本信息
        model.addAttribute("ajzStoreInfo",ajzStoreInfo);
        //或者默认一个父级机构的名称
        Office office = new Office();
        office.setParentCode(ajzStoreInfo.getOffice().getParentCode());
        List<Office> officeList = officeService.findList(office);
        model.addAttribute("officeList",officeList);
        //获得微信jssdk签名等
        QyConfigUtil.getJSSDKSign(request,model);
        //时间戳
        model.addAttribute("Timestamp", TIMESTAMP);
        return "modules/ajz/mobile/update_store_baseinfo";
    }

    //添加门店
    // todo 需要做一个判断，及createBy有值时实体类.preInsert();不执行，但日期时间照常修改
    @RequestMapping(value = "addInfo")
    public String addQYInfo(AjzStoreInfo ajzStoreInfo, AjzNaturalGas ajzNaturalGas, AjzLiquefiedGas ajzLiquefiedGas, AjzFoodSafety ajzFoodSafety, HttpServletRequest request, HttpServletResponse response, Model model) {
        //获取用户数据
        String userId = QyConfigUtil.getUserId(request, response);
        //传入门店数据
        ajzStoreInfo.setSignboard(request.getParameter("signboard"));
        ajzStoreInfo.setEmpCount(request.getParameter("mdxfEmpCount"));
        ajzStoreInfo.setArea(request.getParameter("mdxfArea"));
        ajzStoreInfo.setAddr(request.getParameter("mdxfAddr"));
        ajzStoreInfo.setContactPersonTel(request.getParameter("mdxfContactPersonTel"));
        ajzStoreInfo.setContactPerson(request.getParameter("mdxfContactPerson"));
        ajzStoreInfo.setEnterpriseNum(request.getParameter("mdxfEnterpriseNum"));
        ajzStoreInfo.setEnterpriseName(request.getParameter("mdxfEnterpriseName"));
        //传入用户数据
        ajzStoreInfo.setUpdateBy(userId);
        ajzStoreInfo.setCreateBy(userId);
        ajzNaturalGas.setCreateBy(userId);
        ajzNaturalGas.setUpdateBy(userId);
        ajzLiquefiedGas.setCreateBy(userId);
        ajzLiquefiedGas.setUpdateBy(userId);
        ajzFoodSafety.setCreateBy(userId);
        ajzFoodSafety.setUpdateBy(userId);


        //记录的创建者默认为system，所以ajzRecord可以不用设置system。ajzRecord此处必须设置为system的原因是未排查的数据不需要被统计（及按照人名统计时，可以不计入统计内）
//        AjzRecord ajzRecord = new AjzRecord();
//        ajzRecord.setCheckStatus("0");
//        ajzRecord.setBaseType("store");
////        ajzRecord.setTableType("ajz_store");//(临时)
//        ajzStoreInfo.setAjzRecord(ajzRecord);
        String signboardPic = request.getParameter("imgBox2");
        String enterprisePicture = request.getParameter("imgBox3");

        String officeName = EmpUtils.getOffice(ajzStoreInfo.getOffice().getOfficeCode()).getOfficeName();

        //创建保存在文件管理器中的文件路径
        String filePath = Global.getUserfilesBaseDir(officeName + File.separator + "门店" + File.separator + ajzStoreInfo.getEnterpriseName() + File.separator);
        //创建保存数据库的图片路径
        String savePath = request.getContextPath() + File.separator + "userfiles" + File.separator + officeName + File.separator + "门店" + File.separator + ajzStoreInfo.getEnterpriseName() + File.separator;
        FileUtils.createDirectory(filePath);


//        保存户外照片
        if (!StringUtils.isBlank(signboardPic)) {
            signboardPic = DloadImgUtil.downloadMedia(QyConfigUtil.getAccessToken(), "outdoor", signboardPic, savePath, filePath);
        }
//        保存营业照片
        if (!StringUtils.isBlank(enterprisePicture)) {
            enterprisePicture = DloadImgUtil.downloadMedia(QyConfigUtil.getAccessToken(), "cert", enterprisePicture, savePath, filePath);
        }
        ajzStoreInfo.setSignboardPic(signboardPic);
        ajzStoreInfo.setEnterprisePicture(enterprisePicture);

        ajzStoreInfo.setCycleIndex("1");
        ajzStoreInfo.setCheckStatus("0"); //默认为未检查

        //需要给创建的东西添加用户
        ajzStoreInfoService.save(ajzStoreInfo);
//        保存记录需要添加企业的id，所以需要放在企业保存之后
        //获取企业id
        String ajzStoreInfoId = ajzStoreInfo.getId();
        //保存信息
//        ajzRecord.setBaseId(ajzStoreInfoId);
//        ajzRecordService.save(ajzRecord);
//        //recordProcess也需添加一条
//        ajzRecordProcessService.saveRecord(ajzRecord);
        //保存天然气的信息
        ajzNaturalGas.setBaseId(ajzStoreInfoId);
        ajzNaturalGasService.save(ajzNaturalGas);
        //保存液化气的信息
        ajzLiquefiedGas.setBaseId(ajzStoreInfoId);
        ajzLiquefiedGasService.save(ajzLiquefiedGas);
        //保存食品安全的信息
        ajzFoodSafety.setBaseId(ajzStoreInfoId);
        ajzFoodSafetyService.save(ajzFoodSafety);

        ServletUtils.redirectUrl(request, response, adminPath + "/ajz/ajzBaseinfo/searchName?id=" + ajzStoreInfo.getId());

        return null;
    }

    //记录流程:跳转提交记录页面
    @RequestMapping(value = "record")
    public String record(AjzStoreInfo ajzStoreInfo, HttpServletRequest request, HttpServletResponse response, Model model) throws Exception {

        //获取检查人员信息
        String userCode = CookieUtils.getCookie(request, "userId");
        if(StringUtils.isBlank(userCode)){
            userCode = request.getParameter("user");
        }
        User user = UserUtils.getByLoginCode(userCode);

        //测试从其他地方进来
        if (user == null) {
            user = UserUtils.getByLoginCode("admin");
        }

        //获取上次的检查记录
        List<AjzCheck> ajzChecks= new ArrayList<>();
        List<AjzCheck> orderList=new ArrayList<>();
        List<AjzCheck> rectofication = new ArrayList<>();
        AjzRecord ajzRecord = ajzRecordService.findInfoById(ajzStoreInfo.getId(),request.getParameter("tableType"));
        if(ajzRecord !=null){
            ajzChecks = ajzCheckService.findListByRecordProcessId(ajzRecordProcessService.findForNum(ajzRecord.getNumber()).getId());
            //将list进行深度复制
            orderList = ajzStoreInfoService.deepCopy(ajzChecks);
            rectofication = ajzStoreInfoService.deepCopy(ajzChecks);
            //过滤掉不要的隐患问题
            orderList = ajzStoreInfoService.filter(orderList, "2");
            rectofication = ajzStoreInfoService.filter(rectofication, "1");
        }

        //获取上次的检查点图片和隐患图片
        String checkUrls =  ajzRecord == null ? "" : ajzRecord.getScenePic();
        String dangerUrls =  ajzRecord == null ? "" : ajzRecord.getDangerPic();
        String[] ckls = null;
        String[] dgls = null;
        if (StringUtils.isNotBlank(checkUrls)) {
            ckls = checkUrls.split(";");
        }
        if (StringUtils.isNotBlank(dangerUrls)) {
            dgls = dangerUrls.split(";");
        }

        //获取当前用户所在机构的其他用户
        EmpUser empUser = empUserService.get(user.getUserCode());
        Employee employee = new Employee();
        if (empUser != null) {
            employee = empUser.getEmployee();
        }

        Employee otherUser = new Employee();
        otherUser.setOffice(employee.getOffice());

        EmpUser empUser1 = new EmpUser();
        empUser1.setEmployee(otherUser);

        List userList = empUserService.findList(empUser1);

        model.addAttribute("userList", userList); //返回执法人员的列表
        model.addAttribute("ckls", ckls);
        model.addAttribute("dgls", dgls);
        model.addAttribute("ajzChecks", ajzChecks); //返回复查信息
        model.addAttribute("orderList", orderList); //责令项list
        model.addAttribute("rectofication", rectofication); //待整改项list
        model.addAttribute("user", user);
        model.addAttribute("ajzStoreInfo", ajzStoreInfo);
        model.addAttribute("record", ajzRecord);
        model.addAttribute("tableType", request.getParameter("tableType"));

        //cookie 存值为ajz_aqsc
        CookieUtils.setCookie(response, "store", ajzStoreInfo.getId());

        //获得微信jssdk签名等
        QYAPIConfig qyapiConfig = QyConfigUtil.getQYAPIConfig();
        String jsapi_ticket = qyapiConfig.getJsApiTicket();

        String queryString = request.getQueryString();
        String url2 = "http://" + request.getServerName() // 服务器地址
                + request.getContextPath() // 项目名称
                + request.getServletPath(); // 请求页面或其他地址
        if (queryString != null) {
            url2 += "?" + queryString;
        }
        Map<String, String> sign = WeixinJSSDKSignUtil.sign(jsapi_ticket, url2);

        //获取隐患模板的信息,包括类型和内容

        AjzModel ajzModel = new AjzModel();
        AjzModelContent ajzModelContent = new AjzModelContent();
        ajzModel.setBaseType(request.getParameter("tableType"));
        List<AjzModel> modelList = ajzModelService.findList(ajzModel);
        List<AjzModelContent> ajzModelContentList = new ArrayList<>();

        Map danModel = new LinkedHashMap<>();
        for (AjzModel am:modelList) {
            ajzModelContent.setModelId(am.getId());
            ajzModelContentList = ajzModelContentService.findList(ajzModelContent);
            danModel.put(am.getDangerType(), ajzModelContentList);
        }

        model.addAttribute("danModel", danModel);
        model.addAttribute("appId", QyConfigUtil.apiConfig.getCorpid());
        model.addAttribute("nonceStr", sign.get("nonceStr"));
        model.addAttribute("timestamp", sign.get("timestamp"));
        model.addAttribute("signature", sign.get("signature"));

        //开始检查的时间
        model.addAttribute("starTime", DateUtils.getDateTime());

        //时间戳
        model.addAttribute("Timestamp", TIMESTAMP);

        return "modules/ajz/mobile/table_store";
    }

    //记录流程:记录提交，展示记录页面
    @RequestMapping(value = "recordCommit")
    public String recordCommit(AjzStoreInfo ajzStoreInfo, HttpServletRequest request, HttpServletResponse response, Model model) throws IOException {

        //生成recordProcessId
        String recordProcessId = UUID.randomUUID().toString().replaceAll("-", "");

        //保存记录信息
        AjzRecord ajzRecord = ajzStoreInfoService.saveCmtRecord(recordProcessId,ajzStoreInfo,request);

        //保存问题项,
        List<AjzCheck> ajzChecksList = ajzStoreInfoService.saveCmtCheck(recordProcessId,ajzStoreInfo,request);

        //保存生成文书,返回建议用于推送
        ajzStoreInfoService.saveCmtFile(ajzRecord,ajzChecksList,ajzStoreInfo,request);



        //========================================================服务号消息推送=======================================================================================
        try{
            String opinion = "";
            if(StringUtils.isNotBlank(opinion) && ajzStoreInfo!=null && StringUtils.isNotBlank(ajzStoreInfo.getOpenid())){
                //1.获取问题项目
                opinion = opinion.substring(0, 11)+"......";
                //2.封装消息内容
                Map<String, Object> map = new HashMap<>();
                map.put("first","您有一条新的检查消息通知：\r\n");
                map.put("keyword1","安全生产");
                map.put("keyword2",request.getParameter("starTime"));
                map.put("keyword3",opinion+"\r\n");
                map.put("remark","详情查看具体内容");
                //3.发送消息
                resultTemplateMsgUtil.sendWord(ajzStoreInfo.getOpenid(),map);
            }
        }catch (Exception e){
            System.out.println("erro:"+e);
        }finally {
            ServletUtils.redirectUrl(request, response, adminPath + "/ajz/ajzBaseinfo/searchName?id=" + ajzStoreInfo.getId());
            return "null";
        }

    }
    //修改:跳转到企业修改页面
    @RequestMapping(value = "updatestore")
    public String updatestore(AjzStoreInfo ajzStoreInfo ,HttpServletRequest request, HttpServletResponse response, Model model) {
        //获取用户数据
        String userId = QyConfigUtil.getUserId(request,response);
        if(userId==null){
            userId = "system";
        }
        //传入用户数据
        ajzStoreInfo.setUpdateBy(userId);
        if (ajzStoreInfo.getAjzNaturalGas() != null) {
            ajzStoreInfo.getAjzNaturalGas().setUpdateBy(userId);
        }
        if (ajzStoreInfo.getAjzLiquefiedGas() != null) {
            ajzStoreInfo.getAjzLiquefiedGas().setUpdateBy(userId);
        }
        if (ajzStoreInfo.getAjzFoodSafety() != null) {
            ajzStoreInfo.getAjzFoodSafety().setUpdateBy(userId);
        }


        String signboardPic = request.getParameter("imgBox2");
        String enterprisePicture = request.getParameter("imgBox3");

        String addr = request.getParameter("Addr");
        ajzStoreInfo.setAddr(addr);


        //创建保存在文件管理器中的文件路径
        String filePath =  Global.getUserfilesBaseDir(ajzStoreInfo.getOffice().getOfficeName() + File.separator + "门店" + File.separator +ajzStoreInfo.getEnterpriseName() + File.separator );
        //创建保存数据库的图片路径
        String savePath = request.getContextPath() + File.separator +"userfiles"+ File.separator + ajzStoreInfo.getOffice().getOfficeName() + File.separator + "门店" + File.separator +ajzStoreInfo.getEnterpriseName() + File.separator;
        FileUtils.createDirectory(filePath);

//        保存户外照片,如果不为空的时候，则修改图片
        if (StringUtils.isNotBlank(signboardPic)) {
            signboardPic = DloadImgUtil.downloadMedia(QyConfigUtil.getAccessToken(),"outdoor",signboardPic, savePath, filePath);
            ajzStoreInfo.setSignboardPic(signboardPic);
        }
//        保存营业照片,如果不为空的时候，则修改图片
        if (StringUtils.isNotBlank(enterprisePicture)) {
            enterprisePicture = DloadImgUtil.downloadMedia(QyConfigUtil.getAccessToken(), "cert",enterprisePicture, savePath, filePath);
            ajzStoreInfo.setEnterprisePicture(enterprisePicture);
        }


        //需要给创建的东西添加用户
        ajzStoreInfoService.update(ajzStoreInfo);
//        ajzNaturalGasService.update(ajzStoreInfo.getAjzNaturalGas());
//        ajzLiquefiedGasService.update(ajzStoreInfo.getAjzLiquefiedGas());
//        ajzFoodSafetyService.update(ajzStoreInfo.getAjzFoodSafety());
        ajzCompanyInfoService.updateTypesInvolved(
                ajzStoreInfo.getAjzNaturalGas(),
                ajzStoreInfo.getAjzLiquefiedGas(),
                ajzStoreInfo.getAjzFoodSafety(),
                ajzStoreInfo.getId());
        System.out.println(ajzStoreInfo.getId());

        ServletUtils.redirectUrl(request, response, adminPath + "/ajz/ajzBaseinfo/searchName?id=" + ajzStoreInfo.getId());

        return null;
    }

    @RequestMapping(value = "checkEnterpriseNum")
    @ResponseBody
    public AjzStoreInfo checkEnterpriseNum(AjzStoreInfo ajzStoreInfo,HttpServletRequest request, HttpServletResponse response) {
        AjzStoreInfo ajzStoreInfo1 = ajzStoreInfoService.findajzStoreInfoByEnterpriseId(ajzStoreInfo.getEnterpriseNum());
        return ajzStoreInfo1;
    }


    //后台店面导出
    @RequiresPermissions("sys:empUser:view")
    @RequestMapping(value = "exportStore")
    public void exportStore(HttpServletResponse response,AjzStoreInfo ajzStoreInfo) {

        List<AjzStoreInfo> storeList = ajzStoreInfoService.findList(ajzStoreInfo);
        String fileName = "用户数据" + DateUtils.getDate("yyyyMMddHHmmss") + ".xlsx";
        try (ExcelExport ee = new ExcelExport("用户数据", AjzStoreInfo.class)) {
            ee.setDataList(storeList).write(response, fileName);
        }
    }


}